
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 12/17/2012 20:54:15
-- Generated from EDMX file: C:\Sites\AMAP\AMAP\Domain\AMAPModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [AMAP];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_AmapSupplier]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SupplierSet] DROP CONSTRAINT [FK_AmapSupplier];
GO
IF OBJECT_ID(N'[dbo].[FK_AmapVolunteer]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[VolunteerSet] DROP CONSTRAINT [FK_AmapVolunteer];
GO
IF OBJECT_ID(N'[dbo].[FK_VolunteerVolunteerRole]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[VolunteerRoleSet] DROP CONSTRAINT [FK_VolunteerVolunteerRole];
GO
IF OBJECT_ID(N'[dbo].[FK_RoleVolunteerRole]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[VolunteerRoleSet] DROP CONSTRAINT [FK_RoleVolunteerRole];
GO
IF OBJECT_ID(N'[dbo].[FK_SupplierOffer]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OfferSet] DROP CONSTRAINT [FK_SupplierOffer];
GO
IF OBJECT_ID(N'[dbo].[FK_AmapRequest]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RequestSet] DROP CONSTRAINT [FK_AmapRequest];
GO
IF OBJECT_ID(N'[dbo].[FK_OfferRequest]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RequestSet] DROP CONSTRAINT [FK_OfferRequest];
GO
IF OBJECT_ID(N'[dbo].[FK_OfferOrder]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrderSet] DROP CONSTRAINT [FK_OfferOrder];
GO
IF OBJECT_ID(N'[dbo].[FK_ProductOffer]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OfferSet] DROP CONSTRAINT [FK_ProductOffer];
GO
IF OBJECT_ID(N'[dbo].[FK_ProductExternalOrder]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ExternalOrderSet] DROP CONSTRAINT [FK_ProductExternalOrder];
GO
IF OBJECT_ID(N'[dbo].[FK_AmapExternalOrder]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ExternalOrderSet] DROP CONSTRAINT [FK_AmapExternalOrder];
GO
IF OBJECT_ID(N'[dbo].[FK_BasketComposition]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CompositionSet] DROP CONSTRAINT [FK_BasketComposition];
GO
IF OBJECT_ID(N'[dbo].[FK_BasketExternalComposition]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ExternalCompositionSet] DROP CONSTRAINT [FK_BasketExternalComposition];
GO
IF OBJECT_ID(N'[dbo].[FK_ExternalOrderExternalComposition]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ExternalCompositionSet] DROP CONSTRAINT [FK_ExternalOrderExternalComposition];
GO
IF OBJECT_ID(N'[dbo].[FK_OrderComposition]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CompositionSet] DROP CONSTRAINT [FK_OrderComposition];
GO
IF OBJECT_ID(N'[dbo].[FK_PlaceClient]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ClientSet] DROP CONSTRAINT [FK_PlaceClient];
GO
IF OBJECT_ID(N'[dbo].[FK_QuarterSubscription]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SubscriptionSet] DROP CONSTRAINT [FK_QuarterSubscription];
GO
IF OBJECT_ID(N'[dbo].[FK_ClientSubscription]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SubscriptionSet] DROP CONSTRAINT [FK_ClientSubscription];
GO
IF OBJECT_ID(N'[dbo].[FK_BasketBasketOrder]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BasketOrderSet] DROP CONSTRAINT [FK_BasketBasketOrder];
GO
IF OBJECT_ID(N'[dbo].[FK_ClientBasketOrder]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BasketOrderSet] DROP CONSTRAINT [FK_ClientBasketOrder];
GO
IF OBJECT_ID(N'[dbo].[FK_BasketDelivery]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DeliverySet] DROP CONSTRAINT [FK_BasketDelivery];
GO
IF OBJECT_ID(N'[dbo].[FK_ClientDelivery]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DeliverySet] DROP CONSTRAINT [FK_ClientDelivery];
GO
IF OBJECT_ID(N'[dbo].[FK_UserClient]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ClientSet] DROP CONSTRAINT [FK_UserClient];
GO
IF OBJECT_ID(N'[dbo].[FK_CoordinatesUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CoordinatesSet] DROP CONSTRAINT [FK_CoordinatesUser];
GO
IF OBJECT_ID(N'[dbo].[FK_SupplierUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SupplierSet] DROP CONSTRAINT [FK_SupplierUser];
GO
IF OBJECT_ID(N'[dbo].[FK_VolunteerUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[VolunteerSet] DROP CONSTRAINT [FK_VolunteerUser];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[AmapSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AmapSet];
GO
IF OBJECT_ID(N'[dbo].[SupplierSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SupplierSet];
GO
IF OBJECT_ID(N'[dbo].[VolunteerSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[VolunteerSet];
GO
IF OBJECT_ID(N'[dbo].[ClientSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ClientSet];
GO
IF OBJECT_ID(N'[dbo].[CoordinatesSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CoordinatesSet];
GO
IF OBJECT_ID(N'[dbo].[UserSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserSet];
GO
IF OBJECT_ID(N'[dbo].[RoleSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RoleSet];
GO
IF OBJECT_ID(N'[dbo].[VolunteerRoleSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[VolunteerRoleSet];
GO
IF OBJECT_ID(N'[dbo].[OfferSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OfferSet];
GO
IF OBJECT_ID(N'[dbo].[RequestSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RequestSet];
GO
IF OBJECT_ID(N'[dbo].[OrderSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrderSet];
GO
IF OBJECT_ID(N'[dbo].[ProductSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProductSet];
GO
IF OBJECT_ID(N'[dbo].[ExternalOrderSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ExternalOrderSet];
GO
IF OBJECT_ID(N'[dbo].[BasketSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BasketSet];
GO
IF OBJECT_ID(N'[dbo].[CompositionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CompositionSet];
GO
IF OBJECT_ID(N'[dbo].[ExternalCompositionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ExternalCompositionSet];
GO
IF OBJECT_ID(N'[dbo].[PlaceSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PlaceSet];
GO
IF OBJECT_ID(N'[dbo].[SubscriptionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SubscriptionSet];
GO
IF OBJECT_ID(N'[dbo].[QuarterSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[QuarterSet];
GO
IF OBJECT_ID(N'[dbo].[BasketOrderSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BasketOrderSet];
GO
IF OBJECT_ID(N'[dbo].[DeliverySet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DeliverySet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'AmapSet'
CREATE TABLE [dbo].[AmapSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [RNA] nchar(10)  NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Address1] nvarchar(100)  NOT NULL,
    [Address2] nvarchar(100)  NULL,
    [PostalCode] nchar(5)  NOT NULL,
    [City] nvarchar(50)  NOT NULL,
    [PhoneNumber] nvarchar(13)  NOT NULL,
    [Latitude] float  NOT NULL,
    [Longitude] float  NOT NULL,
    [Email] nvarchar(100)  NOT NULL,
    [SQLServerLoginName] nvarchar(100)  NOT NULL,
    [ForeignAmapId] int  NOT NULL
);
GO

-- Creating table 'SupplierSet'
CREATE TABLE [dbo].[SupplierSet] (
    [Id] int  NOT NULL,
    [SIRET] nchar(14)  NOT NULL,
    [CompanyName] nvarchar(50)  NOT NULL,
    [AmapId] int  NOT NULL
);
GO

-- Creating table 'VolunteerSet'
CREATE TABLE [dbo].[VolunteerSet] (
    [Id] int  NOT NULL,
    [AmapId] int  NOT NULL
);
GO

-- Creating table 'ClientSet'
CREATE TABLE [dbo].[ClientSet] (
    [Id] int  NOT NULL,
    [PlaceId] int  NOT NULL
);
GO

-- Creating table 'CoordinatesSet'
CREATE TABLE [dbo].[CoordinatesSet] (
    [Id] int  NOT NULL,
    [Address1] nvarchar(100)  NOT NULL,
    [Address2] nvarchar(100)  NULL,
    [PostalCode] nchar(5)  NOT NULL,
    [City] nvarchar(50)  NOT NULL,
    [PhoneNumber] nvarchar(13)  NOT NULL,
    [Latitude] float  NOT NULL,
    [Longitude] float  NOT NULL
);
GO

-- Creating table 'UserSet'
CREATE TABLE [dbo].[UserSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Email] nvarchar(100)  NOT NULL,
    [Password] nvarchar(20)  NOT NULL,
    [LastName] nvarchar(50)  NOT NULL,
    [FirstName] nvarchar(50)  NOT NULL,
    [Valid] bit  NOT NULL,
    [CreationDate] datetime  NOT NULL
);
GO

-- Creating table 'RoleSet'
CREATE TABLE [dbo].[RoleSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(20)  NOT NULL,
    [Description] nvarchar(100)  NOT NULL
);
GO

-- Creating table 'VolunteerRoleSet'
CREATE TABLE [dbo].[VolunteerRoleSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [VolunteerId] int  NOT NULL,
    [RoleId] int  NOT NULL
);
GO

-- Creating table 'OfferSet'
CREATE TABLE [dbo].[OfferSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Unit] nvarchar(50)  NOT NULL,
    [Price] float  NOT NULL,
    [CreationDate] datetime  NOT NULL,
    [Quantity] float  NOT NULL,
    [SupplierId] int  NOT NULL,
    [ProductId] int  NOT NULL,
    [HarvestDate] datetime  NOT NULL
);
GO

-- Creating table 'RequestSet'
CREATE TABLE [dbo].[RequestSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [WantedQuantity] float  NOT NULL,
    [ProvidedQuantity] float  NOT NULL,
    [CreationDate] datetime  NOT NULL,
    [AmapId] int  NOT NULL,
    [OfferId] int  NOT NULL
);
GO

-- Creating table 'OrderSet'
CREATE TABLE [dbo].[OrderSet] (
    [Id] int  NOT NULL,
    [OrderedQuantity] float  NOT NULL,
    [DeliveredQuantity] float  NOT NULL,
    [RemainedQuantity] float  NOT NULL
);
GO

-- Creating table 'ProductSet'
CREATE TABLE [dbo].[ProductSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [ShelfLife] smallint  NOT NULL,
    [Fruit] bit  NOT NULL,
    [Vegetable] bit  NOT NULL,
    [Other] bit  NOT NULL
);
GO

-- Creating table 'ExternalOrderSet'
CREATE TABLE [dbo].[ExternalOrderSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Unit] nvarchar(50)  NOT NULL,
    [Price] float  NOT NULL,
    [CreationDate] datetime  NOT NULL,
    [WantedQuantity] float  NOT NULL,
    [ProvidedQuantity] float  NOT NULL,
    [AmapExternalOrderId] int  NOT NULL,
    [ProductId] int  NOT NULL,
    [AmapId] int  NOT NULL,
    [RemainedQuantity] float  NOT NULL,
    [HarvestDate] datetime  NOT NULL
);
GO

-- Creating table 'BasketSet'
CREATE TABLE [dbo].[BasketSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Price] float  NOT NULL,
    [Week] smallint  NOT NULL,
    [Year] smallint  NOT NULL
);
GO

-- Creating table 'CompositionSet'
CREATE TABLE [dbo].[CompositionSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Quantity] float  NOT NULL,
    [BasketId] int  NOT NULL,
    [OrderId] int  NOT NULL
);
GO

-- Creating table 'ExternalCompositionSet'
CREATE TABLE [dbo].[ExternalCompositionSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Quantity] float  NOT NULL,
    [BasketId] int  NOT NULL,
    [ExternalOrderId] int  NOT NULL
);
GO

-- Creating table 'PlaceSet'
CREATE TABLE [dbo].[PlaceSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Address1] nvarchar(100)  NOT NULL,
    [Address2] nvarchar(100)  NULL,
    [PostalCode] nchar(5)  NOT NULL,
    [City] nvarchar(50)  NOT NULL,
    [PhoneNumber] nvarchar(13)  NOT NULL,
    [DeliveryDay] smallint  NOT NULL
);
GO

-- Creating table 'SubscriptionSet'
CREATE TABLE [dbo].[SubscriptionSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Quantity] smallint  NOT NULL,
    [QuarterId] int  NOT NULL,
    [ClientId] int  NOT NULL,
    [CreationDate] datetime  NOT NULL
);
GO

-- Creating table 'QuarterSet'
CREATE TABLE [dbo].[QuarterSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Price] float  NOT NULL,
    [Index] smallint  NOT NULL,
    [Year] smallint  NOT NULL
);
GO

-- Creating table 'BasketOrderSet'
CREATE TABLE [dbo].[BasketOrderSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [CreationDate] datetime  NOT NULL,
    [Quantity] smallint  NOT NULL,
    [BasketId] int  NOT NULL,
    [ClientId] int  NOT NULL
);
GO

-- Creating table 'DeliverySet'
CREATE TABLE [dbo].[DeliverySet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [BasketId] int  NOT NULL,
    [ClientId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'AmapSet'
ALTER TABLE [dbo].[AmapSet]
ADD CONSTRAINT [PK_AmapSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'SupplierSet'
ALTER TABLE [dbo].[SupplierSet]
ADD CONSTRAINT [PK_SupplierSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'VolunteerSet'
ALTER TABLE [dbo].[VolunteerSet]
ADD CONSTRAINT [PK_VolunteerSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ClientSet'
ALTER TABLE [dbo].[ClientSet]
ADD CONSTRAINT [PK_ClientSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CoordinatesSet'
ALTER TABLE [dbo].[CoordinatesSet]
ADD CONSTRAINT [PK_CoordinatesSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UserSet'
ALTER TABLE [dbo].[UserSet]
ADD CONSTRAINT [PK_UserSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'RoleSet'
ALTER TABLE [dbo].[RoleSet]
ADD CONSTRAINT [PK_RoleSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'VolunteerRoleSet'
ALTER TABLE [dbo].[VolunteerRoleSet]
ADD CONSTRAINT [PK_VolunteerRoleSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'OfferSet'
ALTER TABLE [dbo].[OfferSet]
ADD CONSTRAINT [PK_OfferSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'RequestSet'
ALTER TABLE [dbo].[RequestSet]
ADD CONSTRAINT [PK_RequestSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'OrderSet'
ALTER TABLE [dbo].[OrderSet]
ADD CONSTRAINT [PK_OrderSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProductSet'
ALTER TABLE [dbo].[ProductSet]
ADD CONSTRAINT [PK_ProductSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ExternalOrderSet'
ALTER TABLE [dbo].[ExternalOrderSet]
ADD CONSTRAINT [PK_ExternalOrderSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BasketSet'
ALTER TABLE [dbo].[BasketSet]
ADD CONSTRAINT [PK_BasketSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CompositionSet'
ALTER TABLE [dbo].[CompositionSet]
ADD CONSTRAINT [PK_CompositionSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ExternalCompositionSet'
ALTER TABLE [dbo].[ExternalCompositionSet]
ADD CONSTRAINT [PK_ExternalCompositionSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'PlaceSet'
ALTER TABLE [dbo].[PlaceSet]
ADD CONSTRAINT [PK_PlaceSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'SubscriptionSet'
ALTER TABLE [dbo].[SubscriptionSet]
ADD CONSTRAINT [PK_SubscriptionSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'QuarterSet'
ALTER TABLE [dbo].[QuarterSet]
ADD CONSTRAINT [PK_QuarterSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BasketOrderSet'
ALTER TABLE [dbo].[BasketOrderSet]
ADD CONSTRAINT [PK_BasketOrderSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'DeliverySet'
ALTER TABLE [dbo].[DeliverySet]
ADD CONSTRAINT [PK_DeliverySet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [AmapId] in table 'SupplierSet'
ALTER TABLE [dbo].[SupplierSet]
ADD CONSTRAINT [FK_AmapSupplier]
    FOREIGN KEY ([AmapId])
    REFERENCES [dbo].[AmapSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AmapSupplier'
CREATE INDEX [IX_FK_AmapSupplier]
ON [dbo].[SupplierSet]
    ([AmapId]);
GO

-- Creating foreign key on [AmapId] in table 'VolunteerSet'
ALTER TABLE [dbo].[VolunteerSet]
ADD CONSTRAINT [FK_AmapVolunteer]
    FOREIGN KEY ([AmapId])
    REFERENCES [dbo].[AmapSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AmapVolunteer'
CREATE INDEX [IX_FK_AmapVolunteer]
ON [dbo].[VolunteerSet]
    ([AmapId]);
GO

-- Creating foreign key on [VolunteerId] in table 'VolunteerRoleSet'
ALTER TABLE [dbo].[VolunteerRoleSet]
ADD CONSTRAINT [FK_VolunteerVolunteerRole]
    FOREIGN KEY ([VolunteerId])
    REFERENCES [dbo].[VolunteerSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_VolunteerVolunteerRole'
CREATE INDEX [IX_FK_VolunteerVolunteerRole]
ON [dbo].[VolunteerRoleSet]
    ([VolunteerId]);
GO

-- Creating foreign key on [RoleId] in table 'VolunteerRoleSet'
ALTER TABLE [dbo].[VolunteerRoleSet]
ADD CONSTRAINT [FK_RoleVolunteerRole]
    FOREIGN KEY ([RoleId])
    REFERENCES [dbo].[RoleSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RoleVolunteerRole'
CREATE INDEX [IX_FK_RoleVolunteerRole]
ON [dbo].[VolunteerRoleSet]
    ([RoleId]);
GO

-- Creating foreign key on [SupplierId] in table 'OfferSet'
ALTER TABLE [dbo].[OfferSet]
ADD CONSTRAINT [FK_SupplierOffer]
    FOREIGN KEY ([SupplierId])
    REFERENCES [dbo].[SupplierSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SupplierOffer'
CREATE INDEX [IX_FK_SupplierOffer]
ON [dbo].[OfferSet]
    ([SupplierId]);
GO

-- Creating foreign key on [AmapId] in table 'RequestSet'
ALTER TABLE [dbo].[RequestSet]
ADD CONSTRAINT [FK_AmapRequest]
    FOREIGN KEY ([AmapId])
    REFERENCES [dbo].[AmapSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AmapRequest'
CREATE INDEX [IX_FK_AmapRequest]
ON [dbo].[RequestSet]
    ([AmapId]);
GO

-- Creating foreign key on [OfferId] in table 'RequestSet'
ALTER TABLE [dbo].[RequestSet]
ADD CONSTRAINT [FK_OfferRequest]
    FOREIGN KEY ([OfferId])
    REFERENCES [dbo].[OfferSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OfferRequest'
CREATE INDEX [IX_FK_OfferRequest]
ON [dbo].[RequestSet]
    ([OfferId]);
GO

-- Creating foreign key on [Id] in table 'OrderSet'
ALTER TABLE [dbo].[OrderSet]
ADD CONSTRAINT [FK_OfferOrder]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[OfferSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ProductId] in table 'OfferSet'
ALTER TABLE [dbo].[OfferSet]
ADD CONSTRAINT [FK_ProductOffer]
    FOREIGN KEY ([ProductId])
    REFERENCES [dbo].[ProductSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProductOffer'
CREATE INDEX [IX_FK_ProductOffer]
ON [dbo].[OfferSet]
    ([ProductId]);
GO

-- Creating foreign key on [ProductId] in table 'ExternalOrderSet'
ALTER TABLE [dbo].[ExternalOrderSet]
ADD CONSTRAINT [FK_ProductExternalOrder]
    FOREIGN KEY ([ProductId])
    REFERENCES [dbo].[ProductSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProductExternalOrder'
CREATE INDEX [IX_FK_ProductExternalOrder]
ON [dbo].[ExternalOrderSet]
    ([ProductId]);
GO

-- Creating foreign key on [AmapId] in table 'ExternalOrderSet'
ALTER TABLE [dbo].[ExternalOrderSet]
ADD CONSTRAINT [FK_AmapExternalOrder]
    FOREIGN KEY ([AmapId])
    REFERENCES [dbo].[AmapSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AmapExternalOrder'
CREATE INDEX [IX_FK_AmapExternalOrder]
ON [dbo].[ExternalOrderSet]
    ([AmapId]);
GO

-- Creating foreign key on [BasketId] in table 'CompositionSet'
ALTER TABLE [dbo].[CompositionSet]
ADD CONSTRAINT [FK_BasketComposition]
    FOREIGN KEY ([BasketId])
    REFERENCES [dbo].[BasketSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BasketComposition'
CREATE INDEX [IX_FK_BasketComposition]
ON [dbo].[CompositionSet]
    ([BasketId]);
GO

-- Creating foreign key on [BasketId] in table 'ExternalCompositionSet'
ALTER TABLE [dbo].[ExternalCompositionSet]
ADD CONSTRAINT [FK_BasketExternalComposition]
    FOREIGN KEY ([BasketId])
    REFERENCES [dbo].[BasketSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BasketExternalComposition'
CREATE INDEX [IX_FK_BasketExternalComposition]
ON [dbo].[ExternalCompositionSet]
    ([BasketId]);
GO

-- Creating foreign key on [ExternalOrderId] in table 'ExternalCompositionSet'
ALTER TABLE [dbo].[ExternalCompositionSet]
ADD CONSTRAINT [FK_ExternalOrderExternalComposition]
    FOREIGN KEY ([ExternalOrderId])
    REFERENCES [dbo].[ExternalOrderSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ExternalOrderExternalComposition'
CREATE INDEX [IX_FK_ExternalOrderExternalComposition]
ON [dbo].[ExternalCompositionSet]
    ([ExternalOrderId]);
GO

-- Creating foreign key on [OrderId] in table 'CompositionSet'
ALTER TABLE [dbo].[CompositionSet]
ADD CONSTRAINT [FK_OrderComposition]
    FOREIGN KEY ([OrderId])
    REFERENCES [dbo].[OrderSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderComposition'
CREATE INDEX [IX_FK_OrderComposition]
ON [dbo].[CompositionSet]
    ([OrderId]);
GO

-- Creating foreign key on [PlaceId] in table 'ClientSet'
ALTER TABLE [dbo].[ClientSet]
ADD CONSTRAINT [FK_PlaceClient]
    FOREIGN KEY ([PlaceId])
    REFERENCES [dbo].[PlaceSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PlaceClient'
CREATE INDEX [IX_FK_PlaceClient]
ON [dbo].[ClientSet]
    ([PlaceId]);
GO

-- Creating foreign key on [QuarterId] in table 'SubscriptionSet'
ALTER TABLE [dbo].[SubscriptionSet]
ADD CONSTRAINT [FK_QuarterSubscription]
    FOREIGN KEY ([QuarterId])
    REFERENCES [dbo].[QuarterSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_QuarterSubscription'
CREATE INDEX [IX_FK_QuarterSubscription]
ON [dbo].[SubscriptionSet]
    ([QuarterId]);
GO

-- Creating foreign key on [ClientId] in table 'SubscriptionSet'
ALTER TABLE [dbo].[SubscriptionSet]
ADD CONSTRAINT [FK_ClientSubscription]
    FOREIGN KEY ([ClientId])
    REFERENCES [dbo].[ClientSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClientSubscription'
CREATE INDEX [IX_FK_ClientSubscription]
ON [dbo].[SubscriptionSet]
    ([ClientId]);
GO

-- Creating foreign key on [BasketId] in table 'BasketOrderSet'
ALTER TABLE [dbo].[BasketOrderSet]
ADD CONSTRAINT [FK_BasketBasketOrder]
    FOREIGN KEY ([BasketId])
    REFERENCES [dbo].[BasketSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BasketBasketOrder'
CREATE INDEX [IX_FK_BasketBasketOrder]
ON [dbo].[BasketOrderSet]
    ([BasketId]);
GO

-- Creating foreign key on [ClientId] in table 'BasketOrderSet'
ALTER TABLE [dbo].[BasketOrderSet]
ADD CONSTRAINT [FK_ClientBasketOrder]
    FOREIGN KEY ([ClientId])
    REFERENCES [dbo].[ClientSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClientBasketOrder'
CREATE INDEX [IX_FK_ClientBasketOrder]
ON [dbo].[BasketOrderSet]
    ([ClientId]);
GO

-- Creating foreign key on [BasketId] in table 'DeliverySet'
ALTER TABLE [dbo].[DeliverySet]
ADD CONSTRAINT [FK_BasketDelivery]
    FOREIGN KEY ([BasketId])
    REFERENCES [dbo].[BasketSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BasketDelivery'
CREATE INDEX [IX_FK_BasketDelivery]
ON [dbo].[DeliverySet]
    ([BasketId]);
GO

-- Creating foreign key on [ClientId] in table 'DeliverySet'
ALTER TABLE [dbo].[DeliverySet]
ADD CONSTRAINT [FK_ClientDelivery]
    FOREIGN KEY ([ClientId])
    REFERENCES [dbo].[ClientSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClientDelivery'
CREATE INDEX [IX_FK_ClientDelivery]
ON [dbo].[DeliverySet]
    ([ClientId]);
GO

-- Creating foreign key on [Id] in table 'ClientSet'
ALTER TABLE [dbo].[ClientSet]
ADD CONSTRAINT [FK_UserClient]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'CoordinatesSet'
ALTER TABLE [dbo].[CoordinatesSet]
ADD CONSTRAINT [FK_CoordinatesUser]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'SupplierSet'
ALTER TABLE [dbo].[SupplierSet]
ADD CONSTRAINT [FK_SupplierUser]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'VolunteerSet'
ALTER TABLE [dbo].[VolunteerSet]
ADD CONSTRAINT [FK_VolunteerUser]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------